package com.xgc.erp.order.sell.service;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Record;
import com.xgc.common.base.service.BaseService;
import com.xgc.common.model.SellOrder;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class SellOrderService extends BaseService {
    private SellOrder dao = new SellOrder().dao();

    @Override
    public Model<?> getDao() {
        return this.dao;
    }

    public SellOrder getSellOrderById(String orderId){
        String sql = Db.getSql("erp.getSellOrderById");
        return dao.findFirst(sql,orderId);
    }

    /**
     * 开单人下拉选择数据
     * [{value:id,text:user_name}]
     * @return
     */
    public List<Record> queryUserIdAndNameRecord(){
        String sql = Db.getSql("erp.queryUserIdAndNameRecord");
        return Db.find(sql);
    }

    /**
     * 批量修改订单状态
     * @param ids 待修改项
     * @param status 状态
     * @param modifier 修改人
     */
    public void modifyStatus(List<Integer> ids, String status, String modifier){
        List<Object> paramList = new ArrayList<>();
        paramList.add(status);
        paramList.add(modifier);
        paramList.add(new Date());
        StringBuilder sql= new StringBuilder("update "+getTable()+" set status = ? , modifier = ? , update_time = ? where "+getPK()+" in (");
        for(int i=0;i<ids.size();i++){
            sql.append("?");
            if(i<ids.size()-1){
                sql.append(",");
            }
            paramList.add(ids.get(i));
        }
        sql.append(")");
        Db.update(sql.toString(),paramList.toArray());
    }


}
